﻿B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=4.2
@EndOfDesignText@
Sub Class_Globals
	Dim App As AWTRIX

	Dim m4() As Short = Array As Short(0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x9cd3, 0xb596, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x9cd3, 0x0, 0x0)
	Dim m0() As Short=Array As Short(0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0)
	Dim m7() As Short=Array As Short(0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0)
	Dim m6() As Short=Array As Short(0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x632c, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0)
	Dim m5() As Short=Array As Short(0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x632c, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0)
	Dim m3() As Short=Array As Short(0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x632c, 0xb596, 0xb596, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x9cd3, 0xb596, 0x0, 0x0, 0x632c, 0xb596, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x9cd3, 0x0, 0x0)
	Dim m2() As Short=Array As Short(0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x9cd3, 0xb596, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0x9cd3, 0x0, 0x0)
	Dim m1() As Short=Array As Short(0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb596, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9cd3, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x632c, 0xb596, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9cd3, 0x0, 0x0)
End Sub

'Initializes the object. You can NOT add parameters to this method!
Public Sub Initialize() As String
	
	App.Initialize(Me,"App")
	
	'change plugin name (must be unique, avoid spaces)
	App.AppName="Moon"
	
	'Version of the App
	App.AppVersion="2.1"
	
	'Description of the App. You can use HTML to format it
	App.AppDescription=$"
	Shows Today's Moon Phase with current viewing information<br />
	<small>Created by AWTRIX</small>
	"$
		
	'SetupInstructions. You can use HTML to format it
	App.SetupInfos= $"
	<b>Nothing to do<br/>
	"$
	
	'How many downloadhandlers should be generated
	App.NeedDownloads=0
	
	
	'Tickinterval in ms (should be 65 by default)
	App.TickInterval=1500
	
	'If set to true AWTRIX will wait for the "finish" command before switch to the next app.
	App.LockApp=False
	
	'needed Settings for this App (Wich can be configurate from user via webinterface)
	App.appSettings=CreateMap()
	
	App.MakeSettings
	Return "AWTRIX20"
End Sub


' ignore
public Sub GetNiceName() As String
	Return App.AppName
End Sub

' ignore
public Sub Run(Tag As String, Params As Map) As Object
	Return App.AppControl(Tag,Params)
End Sub

Sub App_genFrame
	gensky

	Select MoonPhase
		Case 0
			App.drawBMP(13,0,m0,8,8)
		Case 1
			App.drawBMP(13,0,m1,8,8)
		Case 2
			App.drawBMP(13,0,m2,8,8)
		Case 3
			App.drawBMP(13,0,m3,8,8)
		Case 4
			App.drawBMP(13,0,m4,8,8)
		Case 5
			App.drawBMP(13,0,m5,8,8)
		Case 6
			App.drawBMP(13,0,m6,8,8)
		Case 7
			App.drawBMP(13,0,m7,8,8)
	End Select
	
End Sub

Sub gensky 
	
	For i=0 To 7
		App.drawPixel(Rnd(0,31),Rnd(0,7),Array as Int(51,93,159))
	Next

End Sub

Sub MoonPhase As String
	Dim c,e, b As Int
	Dim jd As Double

	Dim Year As Int = DateTime.GetYear(DateTime.Now)
	Dim Month As Int = DateTime.GetMonth(DateTime.Now)
	Dim Day As Int= DateTime.GetDayOfMonth(DateTime.Now)

	If (Month < 3) Then
		Year = Year - 1
		Month = Month + 12
	End If
	Month = Month + 1

	c = 365.25 * Year
	e = 30.6 * Month
	jd = c + e + Day - 694039.09
	jd = jd / 29.53
	b = jd
	jd = jd - b
	b = jd * 8 + 0.5
	b = Bit.And(b, 7)
	Return b
End Sub